home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Pict2Ascii 1.03 / Utils / PL_Utils.h < prev   
Encoding:
Text File  |  1997-05-22  |  2.3 KB  |  83 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    PL_Utils.cp                                        1997 BB's Team inc. All rights reserved.
  3. // =================================================================================
  4. #include <UTextTraits.h>
  5.  
  6. class PL_Utils {
  7.  
  8.     friend class PL_Utils_Init;
  9.  
  10. public:
  11.     static Handle    ForceNewHandle (Handle &, Int32);
  12.     static void        CenterRect        (    Rect *, const Rect &);
  13.     static void        FitRect            (    Rect *, const Rect &);
  14.     static int         CountBits        (    unsigned char);
  15.     static void        PlayNamedSound    (    Str255);
  16.  
  17.     static void        ComputeBBox        (TextTraitsRecord &, Int32 inSize,         Int32 &outWidth,
  18.                                                                         Int32 &outHeight,    Int32    &outAscent);
  19.     static Boolean IsMonoSpace        (Str255 fontName);
  20.     static Int16    RepeatCharWidth(unsigned char = 0);
  21.  
  22. private:
  23.     static unsigned char        sBaseWidthChar;
  24.     static unsigned char        sVersusWidthChar;
  25.     static unsigned char        sWidthRepeat;
  26.     static unsigned char        sMonoTestSize;
  27.     static void Initialize (void);
  28. };
  29.  
  30.  
  31. // ---------------------------------------------------------------------------------
  32. //        • abs
  33. // ---------------------------------------------------------------------------------
  34. template <class T> T abs (const T& in)
  35. {
  36.     if (in < 0)
  37.         return -in;
  38.     else
  39.         return in;
  40. }
  41.  
  42.  
  43. // ---------------------------------------------------------------------------------
  44. //        • ShellSort
  45. // ---------------------------------------------------------------------------------
  46. template <class T>
  47. void ShellSort (T* array, int n, Boolean (*compare) (const T&, const T&) )
  48. {
  49.     int i, j, h;
  50.     T val;
  51.     
  52.     /* Serie quasi-optimale : 1, 4, 13, 40, 121, 364... */
  53.     for (h=1 ; h<n/9 ; h=3*h+1)
  54.         {} ;
  55.     
  56.     /* Increments successifs des series */
  57.     for ( ; h>0 ; h/=3 )
  58.  
  59.         /* Tri de chaque h-serie */
  60.         for ( i=h ; i<n ; i++ ) {
  61.             val = array[j=i];
  62.             while ( j>=h && (*compare)(array[j-h],val) ) {
  63.                 array[j] = array[j-h];
  64.                 j -= h;
  65.             }
  66.             array[j] = val;
  67.         }
  68. }
  69.  
  70. // ---------------------------------------------------------------------------------
  71. //        • PL_Utils_Init
  72. // ---------------------------------------------------------------------------------
  73. // Library initialisation, The C++ Langage, B. Stroustrup (p.356 in the French edition)
  74. class PL_Utils_Init {
  75. public :
  76.     PL_Utils_Init()    { if (count++==0) PL_Utils::Initialize();    }
  77.     ~PL_Utils_Init()    { }
  78. private :
  79.     static int count;
  80. };
  81.  
  82. static PL_Utils_Init aPL_Utils_Init;
  83.